const express = require('express')
const app = express()
const port = 3001


app.listen(port,()=> console.log(`example app listening on ${port}`))
app.use(async(req,res,next) => {
    console.log('first')
    await next()
    console.log('first end')
});
app.use(async (req,res,next) => {
    console.log('async')
    await next()
    await new Promise(
        (resolve) => {
            setTimeout( () => {
                console.log('wait 1000')
                resolve()
            },1000)
        }
    )
    console.log('async end')
})
app.use(async (req,res,next) => {
    console.log('second')
    await next()
    console.log('second end')
});
app.use(async(req,res,next) => {
    console.log('third')
    await next()
    console.log('third end')
});





app.get('/',(req,rej) =>{
    //rej.writeHeader(200, {'Content-Type':'application/json;charset=UTF-8'});
    rej.send('my nodejs is starting')

})